package com.paw.wechat.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lvzihai
 * @date 2022/10/15
 **/
@Configuration
@EnableConfigurationProperties(WxMaProperties.class)
public class WxMaConfiguration {

  @Autowired
  private WxMaProperties wxMaProperties;

  @Bean
  public WxMaService wxMaService() {
    WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
    config.setAppid(wxMaProperties.getAppid());
    config.setSecret(wxMaProperties.getSecret());
    config.setMsgDataFormat(wxMaProperties.getMsgDataFormat());

    WxMaService service = new WxMaServiceImpl();
    service.setWxMaConfig(config);
    return service;
  }


}
